var e = getApp(), t = require("../../../utils/qqmap-wx-jssdk.min.js"), a = void 0;

Page({
    data: {
        name: "",
        code: "",
        userInfo: {},
        hasUserInfo: !1,
        canIUse: wx.canIUse("button.open-type.getUserInfo"),
        sessionKey: "",
        uid: "",
        goLogin: !1
    },
    onLoad: function(o) {
        var n = this, s = this;
        a = new t({
            key: "Z3HBZ-VX3CP-PQVDI-LMW43-7PQB6-SWFFE"
        }), 
        // wx.getLocation({
        //     type: "wgs84",
        //     isHighAccuracy: !0,
        //     success: function(e) {
        //         wx.setStorageSync("latitude", e.latitude), wx.setStorageSync("longitude", e.longitude), 
        //         s.getLocal(e.latitude, e.longitude);
        //     },
        //     fail: function() {
        //         wx.setStorageSync("position", "安徽"), s.getLesson();
        //     }
        // }), 
        wx.login({
            success: function(t) {
                if ("login:ok" == t.errMsg) var a = t.code;
                a && wx.request({
                    url: e.globalData.request_url + "api/zhiweiku/getUserInfo.php",
                    method: "POST",
                    data: {
                        code: a,
                        province: "国家"
                    },
                    header: {
                        "content-type": "application/x-www-form-urlencoded"
                    },
                    success: function(e) {
                        200 == e.data.code && s.setData({
                            session_key: e.data.session_key,
                            openId: e.data.openid,
                            uid: e.data.uid
                        });
                    }
                });
            }
        });
        var i = wx.getStorageSync("hasUserInfo"), r = wx.getStorageSync("phone");
        i || r || s.setData({
            goLogin: !0
        }), e.globalData.userInfo ? this.setData({
            userInfo: e.globalData.userInfo,
            hasUserInfo: !0
        }) : this.data.canIUse ? e.userInfoReadyCallback = function(e) {
            n.setData({
                userInfo: e.userInfo,
                hasUserInfo: !0
            });
        } : wx.getUserInfo({
            success: function(t) {
                e.globalData.userInfo = t.userInfo, n.setData({
                    userInfo: t.userInfo,
                    hasUserInfo: !0
                });
            }
        });
    },
    search: function() {
        var e = /[^\u4E00-\u9FA5]/g;
        return "" == this.data.name ? (wx.showToast({
            title: "请输入姓名",
            icon: "none"
        }), !1) : e.test(this.data.name) ? (wx.showToast({
            title: "请输入正确的姓名",
            icon: "none"
        }), !1) : "" == this.data.code ? (wx.showToast({
            title: "请输入准考证号",
            icon: "none"
        }), !1) : void wx.navigateTo({
            url: "../result/result?name=" + this.data.name + "&code=" + this.data.code
        });
    },
    watchName: function(e) {
        var t = e.detail.value;
        this.setData({
            name: t
        });
    },
    watchCode: function(e) {
        var t = e.detail.value;
        this.setData({
            code: t
        });
    },
    onShareAppMessage: function() {
        return {
            title: "省考小助手",
            path: "/pages/index/index"
        };
    },
    getLocal: function(e, t) {
        a.reverseGeocoder({
            location: {
                latitude: e,
                longitude: t
            },
            success: function(e) {
                var t = e.result.ad_info.province.replace("市", ""), a = e.result.ad_info.city.replace("市", "");
                t = (t = (t = (t = (t = (t = t.replace("省", "")).replace("壮族自治区", "")).replace("回族自治区", "")).replace("维吾尔自治区", "")).replace("自治区", "")).replace("特别行政区", ""), 
                wx.setStorageSync("position", t), wx.setStorageSync("city", a);
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getPhoneNumber: function(t) {
        var a = this, o = t.currentTarget.dataset.url;
        "getPhoneNumber:ok" == t.detail.errMsg && wx.request({
            url: e.globalData.request_url + "api/zhiweiku/getSelf.php",
            data: {
                encryptedData: t.detail.encryptedData,
                iv: t.detail.iv,
                sessionKey: a.data.session_key,
                act: "up_mobile",
                province: "国家",
                uid: a.data.uid
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            method: "post",
            success: function(e) {
                wx.setStorageSync("hasUserInfo", "1"), wx.setStorageSync("openId", a.data.openId), 
                wx.setStorageSync("phone", e.data.phoneNumber), a.setData({
                    goLogin: !1
                }), o && a.search();
            },
            fail: function() {
                a.wxlogin();
            }
        }), "getPhoneNumber:fail user deny" == t.detail.errMsg && wx.showModal({
            title: "提示",
            content: "为了更好的用户体验请先授权"
        });
    }
});